package com.loan.service;

import com.loan.entity.Channel;
import com.loan.repository.ChannelRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by huxudong on 17/7/1.
 */
@Service
public class ChannelService {

    @Autowired
    public ChannelRepository channelRepository;

    public List<Channel> findByFlag(Integer flag ){
        return channelRepository.findByFlagOrderBySort(flag);
    }

    public List<Channel> findByFlagAndIsHot(Integer flag , Integer isHot){
        return channelRepository.findByFlagAndIsHotOrderBySort(flag ,isHot);
    }

    public List<Channel> findTop4ByFlagAndIsHot(Integer flag ,  Integer isHot){
        return channelRepository.findTop4ByFlagAndIsHotOrderBySort(flag , isHot);
    }

    public void save(Channel channel){
        channelRepository.saveAndFlush(channel);
    }


    public void updateHot(Integer isHot , Long id){
        channelRepository.updateHot(isHot,id);
    }

}
